package com.zmj.framework.dao.jdbc;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.zmj.framework.bean.Product;
import com.zmj.framework.bean.ProductIn;
import com.zmj.framework.dao.ProductInDao;

@Repository
public class ProductInDaoJdbc implements ProductInDao {

	@Autowired
	FrmJdbcTemplate jdbcTemplate;

	public ProductIn getProductInById(String id) {
		String tmpSql = "select * from product_in where id=" + id + "";
		List list = this.jdbcTemplate.queryForList(tmpSql, ProductIn.class);
		if ((list == null) || (list.size() == 0)) {
			return null;
		}
		return ((ProductIn) list.get(0));
	}

	public List<ProductIn> getAllProductInListBySpbh(String spbh) {
		String tmpSql = "select * from product_in where spbh='"+spbh+"'";
		List<ProductIn> list = this.jdbcTemplate.queryForList(tmpSql,ProductIn.class);
		return list;
	}

	public int saveProductIn(ProductIn productIn) {
		int ret=jdbcTemplate.update("insert into product_in (spbh, sl, czy, czsj, bz) values("  
				+"'"+productIn.getSpbh()+"', "
				+"'"+productIn.getSl()+"', "
				+"'"+productIn.getCzy()+"', "
				+"now(), "
				+"'"+productIn.getBz()+"' "
				+ ")");
		
		ret=jdbcTemplate.update("update product set " 
				+"kcsl=kcsl+"+productIn.getSl()+", "  
				+"gxrq=now()"  
		        + "where spbh='"+productIn.getSpbh()+"'");
		
		return ret;
	}


}
